package com.calvin.study.multithread.cas;

import java.io.Serializable;
import java.util.concurrent.atomic.AtomicReference;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * 原子引用
 * @ClassName:AtomicReferenceDemo   
 * @Description:TODO(描述这个类的作用)   
 * @author:Calvin.W
 * @date:2022年2月21日 上午8:54:09
 */
public class AtomicReferenceDemo {
	
	public static void main(String[] args) {
		Order order1 = new Order("20220221856001","果冻");
		Order order2 = new Order("202202201314001","饼干");
		
		AtomicReference ar = new AtomicReference();
		ar.set(order1);
        System.out.println(ar.compareAndSet(order1, order2)+"\t"+ar.get().toString());
        System.out.println(ar.compareAndSet(order1, order2)+"\t"+ar.get().toString());
		
	}

}


@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
class Order implements Serializable {
	
	private static final long serialVersionUID = 6523460473927227344L;

	private String orderId;
	
	private String orderName;

}
